
WEB      = web.cgi
CALC     = calc.cgi
DATABASE = database.txt

DIRPERMS      = u=rwx,g=xr,o=x
SCRIPTPERMS   = u=rwx,g=,o=

USER     = jdahern
CGI      = /cs/cgi/people/${USER}
SCRIPTS  = ${CGI}/public_html
DATA     = ${CGI}/
GROUP    = `groups | gawk '{print $$1}'`

########################################################################
# Installing scripts on the CGI server
########################################################################

install: database.txt
	cp ${WEB} ${SCRIPTS}
	chmod ${DIRPERMS} ${SCRIPTS}
	chmod ${SCRIPTPERMS} ${SCRIPTS}/${WEB} 
	chgrp ${GROUP} ${SCRIPTS}
	chgrp ${GROUP} ${SCRIPTS}/${WEB}   
	cp database.txt ${DATA}
	chmod a+rwx ${DATA}/${DATABASE}

errors:
	tail /cs/cgi/logs/error_log

access:
	tail /cs/cgi/logs/access_log

########################################################################
# Test scripts
########################################################################

# welcome page
test1: database.txt
	ruby ${WEB} -w action=""

# OK login
test2: database.txt
	ruby ${WEB} -w action=login username=nopants password=feathers

# wrong user
test3: database.txt
	ruby ${WEB} -w action=login username=scrooge password=feathers

# wrong password
test4: database.txt
	ruby ${WEB} -w action=login username=nopants password=sailor

# go to create account page
test5: database.txt
	ruby ${WEB} -w action='create\ account'

# new user already exists
test6: database.txt
	ruby ${WEB} -w action='save\ account' username=nopants password=blah sex=Male

# save new user
test7: database.txt
	ruby ${WEB} -w action='save\ account' \
                username=luckyboy \
                realname='gladstone\ gander' \
                password=clover \
                sex=Male

# go to edit page 
test8: database.txt
	ruby ${WEB} -w action=edit username=bluehat

# save edits
test9: database.txt
	ruby ${WEB} -w action='save\ edits' \
           username=bluehat \
           name='Dewey\ Duck' \
           sex=Female \
           password=wood \
           nopants-isfriend=yes nopants-how=family \
           redhat-isfriend=yes redhat-how=family \
           greenhat-isfriend=yes greenhat-how=family \
           cheeseboy-isfriend=no cheeseboy-how=nohow \
           lonelygirl13-isfriend=no lonelygirl13-how=nohow 

# view friend
testA: database.txt
	ruby ${WEB} -w action='view\ bluehat'

# new user, illegal username
testB: database.txt
	ruby ${WEB} -w action='save\ account' username=42 password=blah sex=Male

# new user, illegal password
testC: database.txt
	ruby ${WEB} -w action='save\ account' username=goofy password=42 sex=Male

# new user, illegal sex
testD: database.txt
	ruby ${WEB} -w action='save\ account' username=goofy password=yfoog sex=

# reset the database.txt file to database.orig
database.txt: .FORCE
	/bin/cp database.orig database.txt

.FORCE:

########################################################################
# Installing scripts on a mac
########################################################################

installmac: macclean database.txt
	-sudo /bin/rm /home/${USER}/Sites/${DATABASE}
	cp ${WEB} ${DATABASE} /home/${USER}/Sites
	chmod a+rx /home/${USER}/Sites/${WEB}

macerrors:
	tail /var/log/httpd/error_log

macaccess:
	tail /var/log/httpd/access_log

macclean:
	-sudo /bin/rm /tmp/372book.*


runmac:
	open ${LOCALSITE}/${WEB}

########################################################################
# Installing calc script 
########################################################################

installcalc: 
	cp ${CALC} ${SCRIPTS}
	chgrp ${GROUP} ${SCRIPTS}
	chgrp ${GROUP} ${SCRIPTS}/${CALC}
	chmod ${DIRPERMS} ${SCRIPTS}
	chmod ${SCRIPTPERMS} ${SCRIPTS}/${CALC} 

installcalcmac: 
	cp calc.cgi /home/${USER}/Sites
	chmod a+rx /home/${USER}/Sites/calc.cgi

testcalc1:
	ruby calc.cgi -w

testcalc2:
	ruby calc.cgi -w left=6 op=mul right=7 

runcalcmac:
	open ${LOCALSITE}/calc.cgi

